package com.yinda.dt.produce.view;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.yinda.dt.produce.R;

/**
 * 提示对话框
 * <br/>
 * Created by 小灿 on 2017/3/9.
 */

public class HintDialog extends Dialog implements View.OnClickListener {

    private TextView tv_confirm;
    private TextView tv_cancel;
    private TextView tv_content;
    private TextView tv_title;

    private OnClickListener listener;

    public HintDialog(Context context) {
        super(context, R.style.MyDialog);

        setContentView(R.layout.dialog_hint);

        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_content = (TextView) findViewById(R.id.tv_content);
        tv_cancel = (TextView) findViewById(R.id.tv_cancel);
        tv_cancel.setOnClickListener(this);
        tv_confirm = (TextView) findViewById(R.id.tv_confirm);
        tv_confirm.setOnClickListener(this);
    }

    @Override
    public void setTitle(CharSequence title) {
        tv_title.setText(title);
    }

    public void setContent(CharSequence content) {
        tv_content.setText(content);
    }

    public void setCancelButtonEnabled(boolean enabled) {
        if (enabled) {
            tv_cancel.setVisibility(View.VISIBLE);
        } else {
            tv_cancel.setVisibility(View.GONE);
        }

    }

    public void setCancelButtonText(String text) {
        tv_cancel.setText(text);
    }

    public void setConfirmButtonText(String text) {
        tv_confirm.setText(text);
    }

    public void setOnClickListener(OnClickListener listener) {
        this.listener = listener;
    }

    public interface OnClickListener {
        void onConfirm(Dialog dialog);

        void onCancel(Dialog dialog);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tv_cancel) {
            if (listener != null) {
                listener.onCancel(this);
            }
        }
        if (id == R.id.tv_confirm) {
            if (listener != null) {
                listener.onConfirm(this);
            }
        }
    }
}
